home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / CUGUK / APPLICAT / C034.ZIP / DBQTBL.C < prev    next >
Text File  |  2010-11-01  |  3KB  |  181 lines

  1. /* SDB - table output routine */
  2.  
  3. #include "bdscio.h"
  4. #include "dbqdefs.h"
  5.  
  6. #define BINSRT(chr) buffer[bndx++] = chr
  7.  
  8. db_thead(fp,slptr)
  9.     FILE *fp; struct sel *slptr;
  10. {
  11.     struct sattr *saptr;
  12.     int twidth,fwidth,i;
  13.     char *aname;
  14.  
  15.     dbv_lnct = dbv_pgln;
  16.     dbv_page++;
  17.  
  18.     twidth = 0;
  19.     for (saptr = slptr->sl_attrs; saptr != NULL; saptr = saptr->sa_next)
  20.         twidth += saptr->sa_attr->at_size + 2;
  21.  
  22.     if (dbv_pgln < 1000) fprintf(fp,"[ Page: %d ]\n",dbv_page);
  23.     bstart();
  24.     BINSRT('\n');    /* Blank line for spacing */
  25.     for (saptr = slptr->sl_attrs; saptr != NULL; saptr = saptr->sa_next) {
  26.         fwidth = saptr->sa_attr->at_size;
  27.         if ((aname = saptr->sa_name) == NULL)
  28.             aname = saptr->sa_aname;
  29.  
  30.         /* Uppercase with _ changed to spaces */
  31.  
  32.         for (i = 0; i < fwidth; i++)
  33.             if (*aname != 0)
  34.                 BINSRT(toheading(*aname++));
  35.             else
  36.                 BINSRT(' ');
  37.         BINSRT(' ');
  38.         BINSRT(' ');
  39.     }
  40.     bprint(fp);
  41.  
  42.     bstart();
  43.     for (i = 0; i < twidth; i++)
  44.         BINSRT('=');
  45.     bprint(fp);
  46. }
  47.  
  48. int toheading(ch)
  49. char ch;
  50. {
  51.     if (ch == '_')
  52.         return (' ');
  53.     else
  54.         return (toupper(ch));
  55. }
  56.  
  57. db_tfoot(fp,slptr)
  58.     FILE *fp; struct sel *slptr;
  59. {
  60.     struct sattr *saptr;
  61.     int twidth,i;
  62.     char tempst[22]; char *tptr;
  63.  
  64.     twidth = 0;
  65.     for (saptr = slptr->sl_attrs; saptr != NULL; saptr = saptr->sa_next)
  66.         twidth += saptr->sa_attr->at_size + 2;
  67.  
  68.     bstart();
  69.     for (i = 0; i < twidth; i++)
  70.         BINSRT('=');
  71.     bprint(fp);
  72.  
  73. /* Now print totals */
  74.     bstart();
  75.     for (saptr = slptr->sl_attrs; saptr != NULL; saptr = saptr->sa_next) {
  76.         if (saptr->sa_total != NULL) {
  77. /*            flform(saptr->sa_total,saptr->sa_attr->at_size,-1); */
  78.  
  79.               ltoas(&tempst,saptr->sa_total,saptr->sa_attr->at_scale);
  80.             tptr = &tempst;
  81.             i = saptr->sa_attr->at_size - strlen(tptr);
  82.             if (i > 0) while (i--) BINSRT(' ');
  83.             while (*tptr)
  84.                 BINSRT(*tptr++);
  85.             BINSRT(' ');
  86.             BINSRT(' ');
  87.         }
  88.         else {
  89.             i = saptr->sa_attr->at_size + 2;
  90.             while (i--) BINSRT(' ');
  91.         }
  92.     }
  93.     bprint(fp);
  94.  
  95. }
  96.  
  97. db_tentry(fp,slptr)
  98.     FILE *fp; struct sel *slptr;
  99. {
  100.     struct sattr *saptr;
  101.     int fwidth,i;
  102.     char *temptr,tempfl[4];
  103.  
  104.     if (dbv_lnct == 0) {
  105.         fputs("\n\n",fp);
  106.         db_thead(fp,slptr);
  107.     }
  108.  
  109.     dbv_lnct--;
  110.  
  111.     bstart();
  112.     for (saptr = slptr->sl_attrs; saptr != NULL; saptr = saptr->sa_next) {
  113.         fwidth = saptr->sa_attr->at_size;
  114.         temptr = &buffer[bndx];
  115.         for (i = 0; i < fwidth; i++)
  116.             if (saptr->sa_aptr[i] != 0) {
  117.                 BINSRT(saptr->sa_aptr[i]);
  118.                 }
  119.             else {
  120.                 BINSRT(' ');
  121.             }
  122.  
  123.         BINSRT(' ');
  124.         BINSRT(' ');
  125.         buffer[bndx] = EOS;
  126.  
  127.         if (saptr->sa_total != NULL) {
  128.             atols(tempfl,temptr,saptr->sa_attr->at_scale);
  129.             ladd(saptr->sa_total,saptr->sa_total,tempfl);
  130.         }
  131.     }
  132.     bprint(fp);
  133. }
  134.  
  135. bstart()
  136. {
  137.     bndx = 0;
  138. }
  139. /* replaced by macro
  140. binsert(ch)
  141.     int ch;
  142. {
  143.     if (ch)
  144.         if (bndx < TABLEMAX)
  145.         buffer[bndx++] = ch;
  146. }
  147. */
  148. bprint(fp)
  149.     FILE *fp;
  150. {
  151.     buffer[bndx] = EOS;
  152.     fprintf(fp,"%s\n",buffer);
  153. }
  154.  
  155. /* Long field print routine
  156.  
  157. lform(longint,width,scale)
  158. char longint[];
  159. int width, scale;
  160. {
  161.     char wbuf[20];
  162.     char *wptr;
  163.     int i,j;
  164.  
  165.     wptr = wbuf;
  166.  
  167.     ltoas(wbuf,longint,scale);
  168.     i = width - strlen(wbuf);
  169.     if (i > 0)
  170.        while (i--)
  171.         binsert(' ');
  172.     while (*wptr)
  173.         binsert(*wptr--);
  174.  
  175. }
  176. */
  177. le);
  178.     i = width - strlen(wbuf);
  179.     if (i > 0)
  180.        while (i--)
  181.         bins